Attribute VB_Name = "modODBCCMA"
'---------------------------------------------------------------------------------------
'Module     : modODBC
'Author     : Chris Elwell
'Purpose    : This is an example of a CIC integration module. This is for demostration
'           purposes only. You must write the code required to get/writeback data from/to
'           your customer's data source.
'
'           This example uses the AddrVerify.mdb. A DSN is setup as AddrVerify.
'           Regardless of the integration method, CICs must have a module that contains
'           specific sub routines. All of these subs/functions listed below must exist
'           as they are called from the main program.
'
'           Public Function GetData(ByVal strKey As String) As Boolean - this routine is
'               called when the Order ID field loses focus. This is where you would code to
'               get order data from a customer and populate the screen fields. You can create
'               and call as many support routines as necessary. Also, this routine should
'               return a boolean True if getting the order data was succesful and a boolean
'               False if it was not.
'           Public Function GetPickupData(ByVal strKey As String) As Boolean - this routine is
'               called when the Order ID on the FedEx Returns for field loses focus.
'               This operates the same as GetData above but for use obtaining the Pickup From
'               address info on the Call Tag/Express Tag form.
'           Public Sub WriteReply() - this is called after a successful shipment. A typical
'               use would be to write FXRS reply data back to a customer's system, but can be
'               used for anything that you want to have happen after a package is shipped.
'           Public Sub WriteReturnReply() - this is called after a successful Return Label
'               shipment. Use this to write FXRS reply data back to the customer's system.
'               This is called on both regular and online return labels.
'           Public Sub WriteBOLReply() - this is called after a successful FedEx Freight BOL shipment.
'           Public Sub WriteBatchEditReply() - this is called after a successful Batch Error
'           Edit shipment.
'           Public Sub WriteTagReply() - this is called after a successful Call/Express Tag
'           Public Sub WriteCancelTagReply() - this is called after a Call/Express Tag is Canceled
'           Public Sub WriteError() - this is called after an error is returned from FXRS.
'           Public Sub WriteDelete(ByVal strTracking As String) - this is called after a
'               package is successfully deleted.
'           Public Sub WriteReturnDelete(ByVal strTracking As String) - this is called after
'               a successful Return Label delete. Use this to write FXRS reply data back to
'               the customer's system. This is called on both regular and online return labels.
'           Public Sub AfterClose() - this is called after FXRS is closed.
'           Public Sub AfterLocationChange() - this is called after the Current Location is changed
'               on frmShip.
'           Public Sub BeforeClose() - this is called just before an FXRS close transaction
'               is sent and must return a boolean True for the Close to proceed.
'           Public Function BeforeShip() - Return TRUE to continue shipment, False to cancel.
'           Public Sub Initialize() - this is called once on program execution.
'UPDATED    Public Function BeforeBatch() - Return TRUE to process a batch file.
'UPDATED    Public Function BeforeBatchShip() - Return TRUE to process an individual batch transaction.
'           Public Sub AfterBatchShip() - this is called after each shipment in batch processing.
'           Public Sub AfterBatch() - this is called after a completed batch shipment.
'           Public Sub AfterAddrLookup() - this is called after cboCustID, cboContact, and
'                                          cboCompany lose focus
'           Public Sub AfterDeptLostFocus() - this is called after cboDept or f38 loses focus.
'           Public Sub AfterAddrVerifyUpdate() - this is called after the Update button is
'                                            clicked on the Verify Address form.
'           Public Sub AfterAddrVerify(ByVal intStatusCode As Integer) - this is called after
'               Address Verification. The status code indicates 1 address verified, 2 there was
'               a soft error returned, 3 there was a hard error returned.
'NEW        Public Function BuildCustomSPLabel(ByVal strLabel As String) As String - this is called
'               from BuildSPEPLLabel and BuildSPZPLLabel in modSmartPost. This allow CICs to create
'               custom SmartPost labels in either ZPL or EPL.
'---------------------------------------------------------------------------------------
Option Explicit


#If CMA Then

'

Dim m_CNIn As ADODB.Connection
Dim m_CNOut As ADODB.Connection
Dim m_RS As ADODB.Recordset
Dim m_strLine As String
'


'---------------------------------------------------------------------------------------
' Procedure : AfterLostFocus()
' DateTime  : 2/21/2005
' Purpose   : REQUIRED SUB. Can be used as hook to call routines to be executed after
'             cboDept or f38 loses focus.
'---------------------------------------------------------------------------------------
'
Public Sub AfterLostFocus(c1 As Control)
    
    If c1.name = "f38" Then
        'g_clsReg.SetRegistryValue "Carry_f38", frmShip.f38, REG_SZ
    End If
    If c1.name = "f1273" Then
        'g_clsReg.SetRegistryValue "Carry_f1273", Left(frmShip.f1273.Text, 2), REG_SZ
    End If
    If c1.name = "f1274" Then
        If frmShip.f1274.Text <> "" Then
            g_clsReg.SetRegistryValue "Carry_f1274", Left(frmShip.f1274.Text, 2), REG_SZ
        End If
        
        If Left(frmShip.f1274.Text, 2) = "90" Or Left(frmShip.f1274.Text, 2) = "92" Then
            If Left(frmShip.f1273.Text, 2) <> "01" Then frmShip.f1273.Text = "01"
        End If
    End If
    
    If c1.name = "f50" Then
        g_clsReg.SetRegistryValue "Carry_f50", Left(frmShip.f50.Text, 2), REG_SZ
        
        ' 2010-11-03, JFW, TD only per Jose.
        If Left(frmShip.f50.Text, 2) = "US" And g_strTDMasterTrkNbr <> "" Then
            If frmShip.f1482.Value <> 1 Then
                frmShip.f1482.Value = 1
'                If GetSystemName <> "WINXPC9CA96EA3" Then
'                    If frmShip.cboLocationName(0).Text <> "CMA" Then Call frmShip.SetLocationName("CMA")
'                End If
            End If
            If frmShip.optCommodities.Value <> 1 Then frmShip.optCommodities.Value = 1
        Else
            If frmShip.f1482.Value <> 0 Then
                frmShip.f1482.Value = 0
'                If GetSystemName <> "WINXPC9CA96EA3" Then
'                    If frmShip.cboLocationName(0).Text <> "CMA-Canada" Then Call frmShip.SetLocationName("CMA-Canada")
'                End If
            End If
        End If
    End If
    
'    ' 2010-06-03, JFW, From Jose, flow of control on frmShip
'    If c1.name = "f25" Then
'        frmShip.f116.SetFocus
'    End If
'    If c1.name = "f116" Then
'        frmShip.f1670.SetFocus
'    End If
'    If c1.name = "f1670" And c1.Parent.name = "frmShip" Then
'        frmShip.f1274.SetFocus
'    End If
'    If c1.name = "f1274" Then
'        frmShip.cboBoxName.SetFocus
'    End If
'
'    ' 2010-06-03, JFW, From Jose, flow of control on frmMPS
'    If c1.name = "f1670" And c1.Parent.name = "frmMPS" Then
'        frmMPS.cboBoxName.SetFocus
'    End If
'
'    ' 2010-06-03, JFW, From Jose, fake COD default values
'    If c1.name = "f53" And c1.Parent.name = "frmCOD" Then
'        frmCOD.optCollectType(0).Value = 1
'        frmCOD.chkCOD1stPiece.Value = 1
'    End If

End Sub
'

Public Function ClearCommodity() As Boolean

End Function
'
' 2011-05-05, JFW,
Public Function TDAutoCloseEnabled() As Boolean
    TDAutoCloseEnabled = False
End Function
'

Public Function ClearShipScreen() As Boolean

    On Error Resume Next
    frmShip.f38 = g_clsReg.GetRegistryValue("Carry_f38", "")
    frmShip.f50 = g_clsReg.GetRegistryValue("Carry_f50", "")
    frmShip.f75 = g_clsReg.GetRegistryValue("Carry_f75", "")
    frmShip.f1274 = g_clsReg.GetRegistryValue("Carry_f1274", "")

End Function
'

'---------------------------------------------------------------------------------------
' Procedure : Connect()
' DateTime  : 7/5/2004
' Purpose   : Open connection to ODBC test DSN. Instantiate module level recordset.
'---------------------------------------------------------------------------------------
'
Private Function Connect() As Boolean
    On Local Error GoTo Handler
    Dim strDSN As String
    Dim boolSecondTry As Boolean

    If m_CNIn Is Nothing Then
        Set m_CNIn = New ADODB.Connection
    End If
    If m_CNOut Is Nothing Then
        Set m_CNOut = New ADODB.Connection
    End If
    Set m_RS = New ADODB.Recordset

    Connect = True

    Exit Function

Handler:
'    If Not boolSecondTry Then
'        boolSecondTry = True
'        If Err.number = -2147467259 Then
'            Call AddDSN
'            Resume
'        End If
'    End If
    MsgBox Err.Description, , "modODBC.Connect"
    ' Call Kill        'kill connection and recordset

End Function
'

'---------------------------------------------------------------------------------------
' Procedure : GetData()
' DateTime  : 7/5/2004
' Purpose   : REQUIRED SUB. Called from frmShip.f1_LostFocus, which is the OrderID field.
'             Call routines needed to get data from the customer's system and assign the
'             value to the appropriate fields on the Ship form. This example uses ODBC.
'---------------------------------------------------------------------------------------
'
Public Function GetData(ByVal strKey As String) As Boolean
    On Local Error GoTo Handler
    Dim strSelect As String
    Dim strUserPwd As String    'DSN user and password separated by ','
    Dim strUser As String       'DSN user name
    Dim strPwd As String        'DSN user password
    Dim strData As String
    Dim i As Long

'    If g_clsReg.GetRegistryValue("IntegrationLevel", "Writeback") <> "Writeback" _
'    And g_clsReg.GetRegistryValue("IntegrationLevel", "Writeback") <> "Order Lookup" Then
'        GetData = True
'        Exit Function
'    End If

    If m_CNIn Is Nothing Then
        Call Connect
    End If

    ' frmShip.cboCustID = strKey

    If LoadAddrFields("CustID", strKey, frmShip) Then
        frmShip.f25.SetFocus
    Else

    End If

    Call DeleteIntlCommodities(strKey)

    frmShip.f1670.SetFocus
    
    GetData = True
Release:
    ' call kill
    Exit Function
Handler:
    MsgBox Err.Description, , "modODBC.GetData"
    ' Call Kill
    Resume Release

End Function
'---------------------------------------------------------------------------------------
' Procedure : GetPickupData()
' DateTime  : 1/30/2006
' Purpose   : REQUIRED SUB. Called from frmAddTags.f1_LostFocus, which is the OrderID field.
'             Call routines needed to get data from the customer's system and assign the
'             value to the appropriate fields on the Ship form. This example uses ODBC.
'---------------------------------------------------------------------------------------
'
Public Function GetPickupData(ByVal strKey As String) As Boolean


    GetPickupData = True

End Function
'---------------------------------------------------------------------------------------
' Procedure : WriteReply()
' DateTime  : 2/14/2005
' Purpose   : REQUIRED SUB. Called after a successful ship transaction.
'             This example shows how to obtain multiple occurrence fields from the
'             FXRS reply and how to obtain multiple occurrence fields included in the
'             input transaction but not returned in the FXRS reply.
'---------------------------------------------------------------------------------------
'
Public Sub WriteReply()

    On Local Error GoTo Handler

    If frmShip.f1.Visible = True Then
        Call frmShip.SaveAddress(frmShip.f1)
    End If

    frmShip.f1274 = g_clsReg.GetRegistryValue("Carry_f1274", "")

Release:
    Exit Sub

Handler:
    MsgBox "Error, " & Err.Description, , "modODBC.WriteReply"
    'Call Kill
    Resume Release


End Sub
'---------------------------------------------------------------------------------------
' Procedure : WriteReturnReply()
' DateTime  : 7/14/2005
' Purpose   : REQUIRED SUB. Called after a successful return label transaction.
'             This is called for both regular and online return labels.
'---------------------------------------------------------------------------------------
'
Public Sub WriteReturnReply()

End Sub
'---------------------------------------------------------------------------------------
' Procedure : WriteBOLReply()
' DateTime  : 1/11/2006
' Purpose   : REQUIRED SUB. Called after a successful FedEx Freight BOL transaction.
'             This is called for both regular and online return labels.
'---------------------------------------------------------------------------------------
'
Public Sub WriteBOLReply()

End Sub
'---------------------------------------------------------------------------------------
' Procedure : WriteBatchEditReply()
' DateTime  : 1/17/2006
' Purpose   : REQUIRED SUB. Called after a successful Batch Error Edit transaction.
'             This is called for both regular and online return labels.
'---------------------------------------------------------------------------------------
'
Public Sub WriteBatchEditReply()

End Sub
' Procedure : WriteTagReply()
' DateTime  : 1/26/2006
' Purpose   : REQUIRED SUB. Called after a successful Call Tag/Express Tag transaction.
'---------------------------------------------------------------------------------------
'
Public Sub WriteTagReply()

End Sub
' Procedure : WriteCancelTagReply()
' DateTime  : 1/26/2006
' Purpose   : REQUIRED SUB. Called after a successful Cancel Call Tag/Express Tag transaction.
'---------------------------------------------------------------------------------------
'
Public Sub WriteCancelTagReply()

End Sub
'---------------------------------------------------------------------------------------
' Procedure : WriteReturnDelete()
' DateTime  : 7/14/2005
' Purpose   : REQUIRED SUB. Called after a successful return label delete transaction.
'             This is called for both regular and online return labels.
'---------------------------------------------------------------------------------------
'
Public Sub WriteReturnDelete(ByVal strTracking As String)

End Sub
'---------------------------------------------------------------------------------------
' Procedure : WriteError()
' DateTime  : 7/5/2004
' Purpose   : REQUIRED SUB. Can be used as hook to call routines to be executed after
'             an FXRS Error reply transaction.
'---------------------------------------------------------------------------------------
'
Public Sub WriteError()
    MsgBox "Shipping Error: " & g_str3, vbCritical, "FSMS Error"
End Sub
'---------------------------------------------------------------------------------------
' Procedure : WriteDelete()
' DateTime  : 7/5/2004
' Purpose   : REQUIRED SUB. Can be used as hook to call routines to be executed after
'             successful FXRS Delete.
' Called    : frmShip g_clsParser_Parsecomplete() event on FSMS 123 reply
'---------------------------------------------------------------------------------------
'
Public Sub WriteDelete(ByVal strTracking As String)

End Sub
'---------------------------------------------------------------------------------------
' Procedure : AfterClose()
' DateTime  : 7/5/2004
' Purpose   : REQUIRED SUB. Can be used as hook to call routines to be executed after
'             FXRS Close.
'---------------------------------------------------------------------------------------
'
Public Sub AfterClose()

End Sub
'

' 2007-04-13, JFW, Allow for custom screen display.
Public Sub AfterConnect()

    ' 2007-12-07, JFW, Large address book making a slow start on some clients.
    ' Call frmShip.ToggleLookup(True)
    On Error Resume Next
    'Call frmShip.ToggleDepartment(True)
    frmShip.f70.ListIndex = 0
    frmShip.f72.ListIndex = 0
    frmShip.f38 = g_clsReg.GetRegistryValue("Carry_f38", "")
    frmShip.f50 = g_clsReg.GetRegistryValue("Carry_f50", "")
    frmShip.f75 = g_clsReg.GetRegistryValue("Carry_f75", "")
    frmShip.f1274 = g_clsReg.GetRegistryValue("Carry_f1274", "")

    Call Initialize(frmShip)
    
End Sub
'

'---------------------------------------------------------------------------------------
' Procedure : BeforeClose()
' DateTime  : 7/12/2006
' Purpose   : REQUIRED SUB. Can be used as hook to call routines to be executed before
'             FXRS Close.
'---------------------------------------------------------------------------------------
'
Public Function BeforeClose() As Boolean

    BeforeClose = True

End Function
'

'---------------------------------------------------------------------------------------
' Procedure : BeforeShip()
' DateTime  : 2/21/2005
' Purpose   : REQUIRED Function. Modified to Return Boolean which controls whether or not
'             the shipment will continue or be canceled. Return True to continue shipment,
'             False to cancel.
'---------------------------------------------------------------------------------------
'
Public Function BeforeShip(Optional ByRef TransString As String = "") As Boolean

'    If TransString <> "" Then
'        TransactionStripTag TransString, "583"
'        TransactionBuilder TransString, "583", g_str1670
'        TransString = Replace(TransString, "99,""""", "")
'        TransactionBuilder TransString, 99, ""
'    End If

    BeforeShip = True

    If frmShip.f25 = "" Then
        MsgBox "Reference is mandatory.", vbApplicationModal + vbSystemModal
        frmShip.SSTab1.Tab = 0
        frmShip.f25.SetFocus
        BeforeShip = False
    End If

End Function
'

'---------------------------------------------------------------------------------------
' Procedure : BeforeShipTrans()
' DateTime  : 8/7/2008
' Purpose   : REQUIRED Function. Modified to Return Boolean which controls whether or not
'             the shipment will continue or be canceled. Return True to continue shipment,
'             False to cancel.
'---------------------------------------------------------------------------------------
'
Public Function BeforeShipTrans(ByRef TransString As String) As Boolean
    
    Dim lngMsgBoxResult As VbMsgBoxResult
    BeforeShipTrans = True
    
End Function
'

'---------------------------------------------------------------------------------------
' Procedure : Initialize()
' DateTime  : 7/5/2004
' Purpose   : REQUIRED SUB. Can be used as hook to call routines to be executed on
'             program execution.
'---------------------------------------------------------------------------------------
'
Public Sub Initialize(Optional f1 As Form)

    On Error Resume Next
    
    If Not f1 Is Nothing Then
        If f1.name = "frmShip" Then
            f1.f38.Text = g_clsReg.GetRegistryValue("Carry_f38", "")
            f1.f50.Text = g_clsReg.GetRegistryValue("Carry_f50", "")
            f1.f75.Text = g_clsReg.GetRegistryValue("Carry_f75", "")
            f1.f1274.Text = g_clsReg.GetRegistryValue("Carry_f1274", "")
            frmShip.cboShipmentType = "All TD"
            
            With f1
                .f116.TabIndex = .f25.TabIndex + 1
                .f1670.TabIndex = .f116.TabIndex + 1
                .f1274.TabIndex = .f1670.TabIndex + 1
                .f1273.TabIndex = .f1274.TabIndex + 1
                .cboBoxName.TabIndex = .f1273.TabIndex + 1
                .f59.TabIndex = .cboBoxName.TabIndex + 1
                .f58.TabIndex = .f59.TabIndex + 1
                .f57.TabIndex = .f58.TabIndex + 1
                .f24.TabIndex = .f57.TabIndex + 1
                .f26.TabIndex = .f24.TabIndex + 1
                .f23.TabIndex = .f26.TabIndex + 1
                .f20.TabIndex = .f23.TabIndex + 1
            End With
        End If
        
        ' 2010-06-03, JFW, From Jose, flow of control on frmMPS
        If f1.name = "frmMPS" Then
            f1.cboBoxName.TabIndex = frmMPS.f1670.TabIndex + 1
            f1.cmdAddMPS.TabIndex = frmMPS.cboBoxName.TabIndex + 1
        End If
        
        ' 2010-06-03, JFW, From Jose, flow of control on frmMPS
        If f1.name = "frmCOD" Then
            f1.optCollectType(1).Value = 1
            f1.chkCOD1stPiece.Value = 1
        End If
        
    End If
    Exit Sub

ErrorExit:
    MsgBox Err.Description, vbApplicationModal, "modODBC.Initialize"

End Sub
'---------------------------------------------------------------------------------------
' Procedure : BeforeBatch()
' DateTime  : 20070621-01 Changed BeforeBatch to return a boolean
' Purpose   : REQUIRED SUB. Called before an entire batch is processed.
'---------------------------------------------------------------------------------------
'
Public Function BeforeBatch() As Boolean

    BeforeBatch = True

End Function
'---------------------------------------------------------------------------------------
' Procedure : BeforeBatchShip()
' DateTime  : 20070822-02 Modified BeforeBatchShip to return a Boolean.
' Purpose   : REQUIRED SUB. Called just before a batch transaction is sent to the server.
'---------------------------------------------------------------------------------------
'
Public Function BeforeBatchShip() As Boolean

    BeforeBatchShip = True

End Function
'---------------------------------------------------------------------------------------
' Procedure : AfterBatchShip()
' DateTime  : 10/28/2005
' Purpose   : REQUIRED SUB. Called just after a batch transaction has been processed.
'---------------------------------------------------------------------------------------
'
Public Sub AfterBatchShip()

End Sub
'---------------------------------------------------------------------------------------
' Procedure : AfterBatch()
' DateTime  : 4/6/2005
' Purpose   : REQUIRED SUB. Can be used as hook to call routines to be executed after
'             a batch shipment has been completed.
'---------------------------------------------------------------------------------------
'
Public Sub AfterBatch()

End Sub
'---------------------------------------------------------------------------------------
' Procedure : AfterAddrLookup()
' DateTime  : 2/21/2005
' Purpose   : REQUIRED SUB. Can be used as hook to call routines to be executed after
'             cboCustID, cboContact, or cboCompany loses focus.
'---------------------------------------------------------------------------------------
'
Public Sub AfterAddrLookup()
    frmShip.f25.SetFocus
End Sub
'---------------------------------------------------------------------------------------
' Procedure : AfterDeptLostFocus()
' DateTime  : 2/21/2005
' Purpose   : REQUIRED SUB. Can be used as hook to call routines to be executed after
'             f38 loses focus.
'---------------------------------------------------------------------------------------
'
Public Sub AfterDeptLostFocus()

    On Error Resume Next
    g_clsReg.SetRegistryValue "Carry_f38", frmShip.f38, REG_SZ

End Sub
'

' 2007-04-13, JFW, Allow for custom screen display.
Public Sub AfterDisconnect()

    On Error Resume Next
    
End Sub
'

'---------------------------------------------------------------------------------------
' Procedure : AfterAddrVerifyUpdate()
' DateTime  : 9/13/2005
' Purpose   : REQUIRED SUB. Can be used as hook to call routines to be executed after
'             an address has been updated on the Ship form.
'---------------------------------------------------------------------------------------
'
Public Sub AfterAddrVerifyUpdate()

End Sub
'---------------------------------------------------------------------------------------
' Procedure : AfterLocationChange()
' DateTime  : 3/06/2006
' Purpose   : REQUIRED SUB. Can be used as hook to call routines to be executed after
'             the shipping Location has been changed on the Ship form.
'---------------------------------------------------------------------------------------
'
Public Sub AfterLocationChange()

End Sub
'---------------------------------------------------------------------------------------
' Procedure : AfterAddrVerify()
' DateTime  : 5/12/2006
' Purpose   : REQUIRED SUB. Can be used as hook to call routines to be executed after
'             Address Verification. Three possible status codes are passed. See comments
'             below.
'---------------------------------------------------------------------------------------
'
Public Sub AfterAddrVerify(ByVal intStatusCode As Integer)

    Select Case intStatusCode
        'Address is verfified
        Case 1

        'Soft error
        Case 2

        'Hard error
        Case 3

    End Select

End Sub
'---------------------------------------------------------------------------------------
' Procedure : BuildCustomSPLabel()
' DateTime  : 20070620-04
' Purpose   : REQUIRED SUB. Can be used as hook to create custom EPL or ZPL buffer labels
'             for SmartPost.
'---------------------------------------------------------------------------------------
'
Public Function BuildCustomSPLabel(ByVal strLabel As String) As String

    BuildCustomSPLabel = strLabel

End Function
'---------------------------------------------------------------------------------------
' Procedure : AfterRateQuote()
' DateTime  : 20071106-01
' Purpose   : REQUIRED SUB. Can be used as hook to call routines to be executed after
'             a rate quote.
'---------------------------------------------------------------------------------------
'
Public Sub AfterRateQuote()

End Sub

' 2012-01-19, JFW, New for UCS.
Public Function BeforeGotFocus(f As Form, c As Control) As Boolean
    On Error GoTo Test
''    If f.name = "frmShip" Then
''        If c.name = "f26" Then
''            frmShip.f26.Enabled = False
''            frmShip.f26.Text = ""
''        End If
''    End If
    BeforeGotFocus = False
    Exit Function
Test:
    DebugPrint Now & ", " & "BeforeGotFocus" & ", " & Err.Description
    
End Function

'---------------------------------------------------------------------------------------
' Procedure : AfterLocationChange()
' DateTime  : 5/17/2011
' Purpose   : Remove or add custom services.
' 2011-05-17, JFW, New for Scapa
'---------------------------------------------------------------------------------------
'
Public Sub AfterLoadServices(c1 As ComboBox)
 
End Sub


#End If



